/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.patrol.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.patrol.APatrolItem;
import com.thor.palmmall.spi.device.SDeviceCategoryField;

/**
 * @author wolv
 *
 */
public class APatrolItemConverter implements Converter<SDeviceCategoryField, APatrolItem> {

  public static APatrolItemConverter getInstance() {
    if (instance == null)
      instance = new APatrolItemConverter();
    return instance;
  }

  private static APatrolItemConverter instance;

  private APatrolItemConverter() {
  }

  @Override
  public APatrolItem convert(SDeviceCategoryField source) {
    if (source == null)
      return null;

    APatrolItem target = new APatrolItem();
    target.setDefaultValue(source.getDefaultValue());
    target.setEnabled(source.isEnabled());
    target.setLineNo(source.getLineNo());
    target.setName(source.getName());
    target.setNullable(source.isNullable());
    target.setUuid(source.getUuid());
    target.setValueType(source.getFieldType());
    target.setMaxValue(source.getMaxValue());
    target.setMinValue(source.getMinValue());
    target.setEnumValues(new ArrayList<String>());
    if(source.getEnumValues() != null){
      target.getEnumValues().addAll(source.getEnumValues());
    }
    return target;
  }

}
